﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace MaJiang{
	public class MaJiang : MonoBehaviour {
		CardManager cardmgr = new CardManager();
		// Use this for initialization
		void Start () {
			RestCardMgr ();
		}
		
		// Update is called once per frame
		void Update () {
			cardmgr.Update (Time.deltaTime);
		}
		Vector2 sv;
		List<Card> deskCards;
		bool trueCards = false;
		void OnGUI(){
			deskCards = cardmgr.getDeskCards ();
			trueCards = deskCards.Count == 144;
			sv = GUILayout.BeginScrollView (sv);
			DrawTool ();
			DrawDeskCard ();
			GUILayout.EndScrollView ();
		}
		void RestCardMgr(){
			cardmgr.ClearCommand ();
			cardmgr.AddCommand<CMD_WANFA_FUZHOU> ();

		}
		void DrawTool(){
			if (cardmgr.getCurrentCMDName () != MJ_Command.NoCommandName) {
				DrawButton (cardmgr.getCurrentCMDName (), cardmgr.DoCurrentCMD);
			}
			if (cardmgr.isInit) {
				DrawButton ("回合开始",delegate() {
					cardmgr.TurnStrt();
				});
			}
		}

		void DrawButton(string key,System.Action callback){
			if (GUILayout.Button (key,GUILayout.Width(100)))
				callback ();
		}
		void DrawDeskCard(){
			if (deskCards.Count == 144) {
				GUILayout.Label ("剩余牌数:" + cardmgr.surplusCardCount);
				if (GUILayout.Button ("log")) {
					Debug.Log (cardmgr.logMgr.log);
				}
				GUILayout.Label ("当前盘数:" + cardmgr.turnCount);
				GUILayout.Label ("当前回合数:" + cardmgr.gameTurnCount);
				if (cardmgr.currentTouchPlayer != null) {
					GUILayout.Label ("当前玩家:" + cardmgr.currentTouchPlayer.indexName);
				}

			} else {
				GUILayout.Label ("!!!警告 牌数不对:" + deskCards.Count + " != 144 请重新洗牌");
 			}
		}
	}
}
